%{
	#include <stdio.h>	
	#include "../expression/interface.h"
%}

%union {
	double val;
	char* str;
	void* exp;
}

%token	<val> CONSTANT
%token	PLUS MINUS MULTIPLY DIVIDE POW ABS LEFTP RIGHTP
%token	<str> VARIABLE
%token	LN LOG SIN COS

%token	LEFTB RIGHTB SEMICOLON

%token	NL

%type	<exp>	expression color

%left	PLUS MINUS
%left	MULTIPLY DIVIDE
%right	POW

%%

program: expression NL parameters										{ setRoot($1); }
	;

parameters: elementaryDeltas NL
	| elementaryDeltas NL elementaryColors NL
	;

expression: expression PLUS expression									{ $$ = newPlus($1,$3); }
	| expression MINUS expression										{ $$ = newMinus($1,$3); }
	| expression MULTIPLY expression									{ $$ = newMultiply($1,$3); }
	| expression DIVIDE expression										{ $$ = newDivide($1,$3); }
	| expression POW expression											{ $$ = newPow($1,$3); }
    | LEFTP expression RIGHTP              								{ $$ = $2; }
    | ABS expression ABS                    							{ $$ = newAbs($2); }
	/* TODO : hashmap to store functions ? */
	| COS LEFTP expression RIGHTP										{ $$ = newCos($3); }
	| SIN LEFTP expression RIGHTP										{ $$ = newSin($3); }
	| LN LEFTP expression RIGHTP										{ $$ = newLn($3); }
	| LOG LEFTP expression RIGHTP										{ $$ = newLog($3); }
	| VARIABLE															{ $$ = newVariable($<str>1); }
	| CONSTANT															{ $$ = newConstant($<val>1); }
	;

elementaryDeltas: LEFTB expression SEMICOLON expression RIGHTB			{ setDeltaTheta($2); setDeltaPhi($4); }
	;
	
color:	expression														{ $$ = $1; }
	|																	{ $$ = NULL; }
	;
	
elementaryColors: LEFTB color SEMICOLON color SEMICOLON color RIGHTB	{ void* rgb[3]; rgb[0] = $2; rgb[1] = $4; rgb[2] = $6; setRgb(rgb); }
	|
	;
	
%%
